<?php

namespace app\api\model;

use think\helper\Time;

class Cluster extends Common
{
    static public function active($id, $count='1')
    {
        $cluster = self::get($id);

        $time = time();

        if ($cluster['active_day_time'] < Time::today()) {
            $active_day = 0;
        } else {
            $active_day = $cluster['active_day'];
        }

        if ($cluster['active_week_time'] < Time::week()) {
            $active_week = 0;
        } else {
            $active_week = $cluster['active_week'];
        }

        if ($cluster['active_month_time'] < Time::month()) {
            $active_month = 0;
        } else {
            $active_month = $cluster['active_month'];
        }

        self::update([
            'id' => $cluster['id'],
            'active' => $cluster['active'] + $count,
            'active_day' => $active_day + $count,
            'active_day_time' => $time,
            'active_week' => $active_week + $count,
            'active_week_time' => $time,
            'active_month' => $active_month + $count,
            'active_month_time' => $time,
        ]);
    }
}
